package com.sunnada.edu.system.pub.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Transactional
@Service
public class BaseDaoImpl extends SqlSessionDaoSupport implements BaseDao {

/**继承SqlSessionDaoSupport 然后用以下的方法也是可以直接获取，可以不用sqlSession*/
	@Resource
	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		super.setSqlSessionFactory(sqlSessionFactory);
	}
	/*private SqlSession sqlSession;
	public SqlSession getSqlSession() {
		return sqlSession;
	}
	public void setSqlSession(SqlSession sqlSession) {
		this.sqlSession = sqlSession;
	}*/

	public List selectList(String sqlName, HashMap<String, String> params) {
		List list = getSqlSession().selectList(sqlName, params);
		return list; 
	}

	public List selectList(String sqlName, Map<String, String> params) {
		List list = getSqlSession().selectList(sqlName, params);
		return list; 
	}
	
	public int update(String sql) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("sql", sql);
		return getSqlSession().update("base_sqlmap.update", params);
	}

	public int update(String sqlName, HashMap<String, String> params) { 
		return getSqlSession().update(sqlName, params);
	}
	
	public int update(String sqlName, Map<String, Object> params) { 
		return getSqlSession().update(sqlName, params);
	}
 
	public int insert(String sqlName, HashMap<String, String> params) {
		return getSqlSession().insert(sqlName, params);
	}
	
	public int insert(String sqlName, Map<String, String> params) {
		return getSqlSession().insert(sqlName, params);
	}

	public int insert(String sqlName, List<HashMap<String, String>> list) {
		return getSqlSession().insert(sqlName, list);
	}
	
	public int delete(String sqlName, HashMap<String, String> params) {
		return getSqlSession().delete(sqlName, params); 
	}
	
	public int delete(String sqlName, Map<String, String> params) {
		return getSqlSession().delete(sqlName, params); 
	}

	public Map<String,String> selectOneMap(String sqlName, HashMap<String, String> params) {
		return getSqlSession().selectOne(sqlName, params);
	}

	public String selectOneString(String sqlName, HashMap<String, String> params) {
		return getSqlSession().selectOne(sqlName, params);
	}
	
	public String selectOneString(String sqlName) {
		return getSqlSession().selectOne(sqlName);
	}

}
